const db = require('../config/db');

class Article {
  static async getAll() {
    const [rows] = await db.query('SELECT * FROM articles');
    return rows;
  }

  static async getById(id) {
    const [rows] = await db.query('SELECT * FROM articles WHERE id = ?', [id]);
    return rows[0];
  }
  static async create(title, content, author_id, category_id = null, status = 'draft', published_at = null) {
      const [result] = await db.query(
          'INSERT INTO articles (title, content, author_id, category_id, status, published_at) VALUES (?, ?, ?, ?, ?, ?)',
          [title, content, author_id, category_id, status, published_at]
      );
      return result.insertId; // 返回新插入记录的 ID
  }
  // 添加更多方法...
}

module.exports = Article;